package com.synergy.stockflow.sales.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.synergy.stockflow.model.Result;
import com.synergy.stockflow.sales.entity.QuoteDetails;
import com.synergy.stockflow.sales.service.QuoteDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/quoteDetails")
public class QuoteDetailsController {

    @Autowired
    QuoteDetailsService quoteDetailsService;

    @GetMapping("/select")
    public Result<Page<QuoteDetails>> getQuoteDetails(String quoteDetailsQuotationId) {
        Page<QuoteDetails> page = new Page<>(1, 5);
        page.setRecords(quoteDetailsService.selectWL(quoteDetailsQuotationId));
        return Result.success(page);
    }

    @PutMapping("{id}")
    public Result updateQuoteDetails(@RequestBody List<QuoteDetails> quoteDetails,@PathVariable("id")String id) {
        QuoteDetails quoteDetails1=quoteDetails.get(0);
        quoteDetailsService.detect(id);
        for(QuoteDetails q:quoteDetails){
            q.setQuoteDetailsQuotationId(id);
            quoteDetailsService.save(q);
        }

        return Result.success(quoteDetails1);
    }
}
